///////////////////////////////////////////////////
// Election Administration Polarization
// Make RD Analaysis Dataset
///////////////////////////////////////////////////

gl path "~/Library/CloudStorage/GoogleDrive-danmckinleythompson@gmail.com/My Drive/ElecAdminPolarization/How_Partisan_Is_Local_Election_Admin_Replication"

cap prog drop rdtab
do "$path/code/project_commands/rdtab.ado"

* Bring in the presidential election analysis data
use "$path/analysis_data/rd_election_analysis_data.dta", clear
keep if office=="pres"

* Compute the correlation between D pres vs and D clerk vs in counties with pres cycle clerk elections
pwcorr vs_dem_leo lag_vs_dem
pwcorr vs_dem lag_vs_dem
pwcorr vs_dem_leo lag_vs_dem if mod(year, 4)==0
pwcorr vs_dem lag_vs_dem if mod(year, 4)==0


** Plots restricted to pres cycle leo elections

* Plot the relationship between D clerk vs and D pres vs
twoway (scatter vs_dem_leo lag_vs_dem if mod(year, 4)==0, mc(gs4%20) msi(vsmall)) ///
	(lfit vs_dem_leo lag_vs_dem, lc(gs2)), ///
	xsc(r(0 1)) xlab(0(0.2)1) ///
	ysc(r(0 1)) ylab(0(0.2)1) ///
	xti("Dem Pres Vote Share") yti("Dem Clerk Vote Share") ///
	scale(1.4) ///
	legend(off) ///
	graphregion(color(white))
graph export "$path/output/dem_clerk_vs_on_lag_dem_pres_vs.pdf", replace

* Plot the relationship between D pres vs and lagged D pres vs
twoway (scatter vs_dem lag_vs_dem if mod(year, 4)==0, mc(gs4%20) msi(vsmall)) ///
	(lfit vs_dem lag_vs_dem, lc(gs2)), ///
	xsc(r(0 1)) xlab(0(0.2)1) ///
	ysc(r(0 1)) ylab(0(0.2)1) ///
	xti("Lag Dem Pres Vote Share") ///
	yti("Dem Pres Vote Share") ///
	scale(1.4) ///
	legend(off) ///
	graphregion(color(white))
graph export "$path/output/dem_pres_vs_on_lag_dem_pres_vs.pdf", replace

